package com.ie.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.ie.entity.Activity;
import com.ie.entity.vo.ActivityVo;
import com.ie.service.ActivityService;
import com.ie.mapper.ActivityMapper;
import jakarta.annotation.Resource;
import org.springframework.stereotype.Service;

import java.lang.invoke.VarHandle;
import java.text.SimpleDateFormat;
import java.time.format.DateTimeFormatter;
import java.util.*;

/**
* @author admin
* @description 针对表【activity】的数据库操作Service实现
* @createDate 2025-03-02 22:16:12
*/
@Service
public class ActivityServiceImpl
    implements ActivityService{
@Resource
private ActivityMapper activityMapper;
    @Override
    public List<Activity> getAllActivity() {

        return activityMapper.getAllActivity();
    }

    @Override
    public boolean editActivity(Activity activity) {

        return activityMapper.editActivity(activity);
    }

    @Override
    public boolean deleteActivity(String id) {

        return activityMapper.deleteActivity(id);
    }

    @Override
    public List selectList(String name, String type, String city) {
        QueryWrapper wrapper = null;
        Map<String, String> map = new HashMap<>();
        map.put("activityname", name);
        map.put("activitytype", type);
        map.put("city", city);
        wrapper = new QueryWrapper<Activity>().allEq(map, false);

        List<Activity> list = activityMapper.selectList(wrapper);

        SimpleDateFormat formatter = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        List<ActivityVo> voList = new ArrayList<>();
        for (Activity activity : list) {

            ActivityVo vo = new ActivityVo();
            vo.setId(activity.getId());
            vo.setActivityname(activity.getActivityname());
            vo.setActivitytype(activity.getActivitytype());
            vo.setDetails(activity.getDetails());
            vo.setCity(activity.getCity());
            vo.setLocation(activity.getLocation());
            vo.setActivitydate(formatter.format(activity.getActivitydate()));
            vo.setRequiredpeople(activity.getRequiredpeople());
            vo.setSigneduppeople(activity.getSigneduppeople());
            voList.add(vo);
        }

        return voList;
    }
}




